<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of az_checkdata
 *
 * @author Shark
 */
class Az_CheckData {
    
    /*
     * Function validate email
     * True when The pattern allows -,+,_ and . in email
     * address and also allows multi level domains
     * example: programmer88@yahoo.com
     *          smart.programmer@yahoo.com
     *          some1@yahoo.co.uk
     *          kim_nl@email.com
     * Fail:    programmer..88@yahoo.com
     *          abc*88@yahoo.com
     *          programmer@yahoo
     *          programmer@yahoo.abcdefghi
     *          abc.xyz@hotmail.com@nl
     */
    public function validate_email($email) {
        if ($email != null) {
            $regex = "|^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$|";
            if (preg_match($regex, $subject)) {
                return true;
            } else {
                return false;
            }
        }
    }

    /*
     * Function validate strong password
     * True when Validates a strong password.
     * It must be between 8 and 10 characters, 
     * contain at least one digit and one alphabetic character,
     * and must not contain special characters.
     * Example: mankind7
     *          a12345678
     *          master22
     *          abc12345
     * Fail:    mankind
     *          12345678
     *          master@22
     *          abcdefgh
     */

    public function validate_strong_password($pass) {
        if ($pass != null) {
            $regex = "|(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$|";
            if (preg_match($regex, $pass)) {
                return true;
            } else {
                return false;
            }
        }
    }

    /*
     * The regex is used to match a URL of protocol (http,ftp,https). 
     * WWW is optional and a port number at the end is also optional.
     * Example :http://www.google.com
     *          http://google.com
     *          http://www.google.com.nl
     *          http://www.myserver.com:1290
     *          ftp://godaddy.com:8080
     * Fail: http:/www.google.com
     *       www.google.com
     *       http://www.google.com/webmasters
     *       http://localhost:8080
     *       ftp.google.com
     */
    public function validate_url($url) {
        if ($url != null) {
            $regex = "|^((ht|f)tp(s?))\://([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(/\S*)?$|";
            if(preg_match($regex, $url)){
                return true;
            }else{
                return false;
            }
        }
    }
    
    /*
     * To detect alphanumeric characters 
     * only include alpha and numberic
     * Example : mike124
     *           smith
     *           dairyman88
     * Fail:     mike++
     *           richard.123
     *           abc_123
     */
    public function validate_alphanumeric($alphanumeric){
        if($alphanumeric != null){
            $regex ="|[A-Za-z0-9]|";
            if(preg_match($regex, $alphanumeric)){
                return true;
            }else{
                return false;
            }
        }
    }
    
     
    /*
     *  Function check validate numerphone
     *  Example: 071.123456, (84-71). 123456, 
     *           (84-71) 123456, 0913123456, 0913.123456
     */
    public function validate_number($numberphone){
        if($numberphone != null){
            $regex = "|/(\(?(\d|(\d[- ]\d))\)?[-. ]?)?(\d\.?\d\.?\d)/|";
            if(preg_match($regex, $numberphone)){
                return true;
            }else{
                return false;
            }
        }        
    }

}

?>
